import request from '@/utils/request'
import qs from 'qs'
import Cookies from 'js-cookie'

export function login(data) {
  data = qs.stringify(data)
  return request({
    url: '/auth/oauth/token',
    method: 'post',
    data
  })
}

/*
*刷新token
*/
export function refreshToken(data) {
  data = qs.stringify(data)
  return request({
    url: '/auth/oauth/token',
    method: 'post',
    data
  })
}


export function getInfo(token) {
  return request({
    url: '/vue-admin-template/user/info',
    method: 'get',
    params: { token }
  })
}

export function logout() {
  return request({
    url: '/vue-admin-template/user/logout',
    method: 'post'
  })
}

export function fetchList(query) {
  return request({
    url: '/admin123/coding/a2user/a2userAjax_queryListBySearch',
    method: 'get',
    params: query
  })
}

export function createUser(data) {
  return request({
    url: '/admin123/coding/a2user/a2userAjax_addData',
    method: 'post',
    data
  })
}

export function updateUser(data) {
  return request({
    url: '/admin123/coding/a2user/a2userAjax_editData',
    method: 'post',
    data
  })
}

export function removeUser(params) {
  return request({
    url: '/admin123/coding/a2user/a2userAjax_removeData',
    method: 'post',
    params
  })
}

/* export function login(data) {
  data = qs.stringify(data)
  axios({
    method: 'post',
    url: 'http://localhost:7002/auth/oauth/token',
    data: data,
    timeout: 10 * 1000,
    headers: { 'Authorization': 'Basic bWVuZ3h1ZWd1LXBjOm1lbmd4dWVndS1zZWNyZXQ=' }
  }).then(
    (result) => {
      console.log(result)
      console.log(result.data)
    }
  ).catch((err) => {
    console.error(err)
  })
}*/
